
class_title = """# coding=utf-8
import traceback
import requests
import unittest
from Common.FontColor import outcome
from Common.MyUnit import MyTest
from random import choice
from Common.CusMethod import random_code, random_str
from Common.ReadYaml import ConfigYaml,ReadKeyWorld
from Common.DataHandle import ReRun



class {}(MyTest):

    '''
    {}
    '''
    """

case_body = """
    # @unittest.skipIf(condition, "暂时跳过")
    @ReRun(MyTest.setUp)
    def {}(self):
        '''
        {}
        '''
        try:
 
            self.url = ConfigYaml(self.projectName).base_url + self.url
            r = requests.{}(self.url, headers=self.headers, {}=self.data, stream=True, verify=False)
            self.result = r.json()

            self.time = r.elapsed.total_seconds()
        except:
            self.singular = str(traceback.format_exc())
            outcome('red', self.singular)
            return self.singular
        """

case_data = '''%s:  #该字段为项目名称,此子段必须与配置文件的项目名称字段保持一致,如果是通过框架自动生成的用例模板,该字段自动取的项
                    #目名称，若是自己手动建的模板,保持该字段与项目名称一致,该字段为必填项
  product: #产品管理--> 模块名称,自定义可以任意修改,尽量取得有意义，比如：product, order等,该字段为必填项
    - url: /manager-webapi/product/productInformation/list  # 接口地址--> 接口所需要得url，为什么用例里面又有一个url,
    #原因:若多个接口共用个ur(如一个接口边界验证,正向逆向验证),可以省略用例里面url,只写该url,用例里面的接口会自动取该url,
    #若用例里面有url,则自动覆盖该url
      modular: 产品列表  # 接口注释 --> 该字段为模块中文解释，该字段值会自动填充到代码注释中，目的让人明白该模块的主要功能
      className: manage_product  # 接口类名 --> 该字段值为用例类名,可以任意自定义,但是类名必须以下划线分割且最后一个下划线的
      #值为模块名,这两个值必须保持一致,中间可以任意添加多个下划线,为什么要保持一致?原因:因为我们在运行任意用例的时候,我们首先去
      #拿到该用例的用例名称,再通过用例名称反推到该用例的类名,再将类名分割获取到模块名称最后通过关键字一层一层拿到用例所需要的数
      #据并将该数据存储在内存中,该字段为必填项,
      funName:    #该字段为固定关键字，必须这样写，目的用关键字去打包所有测试用例数据
        - test_product_getlist: {  # 接口方法名--> 该字段为测试用例名称,其实就是一个方法名称,必须以test开头,当然可以修
          #改为其他字段开头,但是要修改 unittest源码,本地可以这么干,但是我们遵循源码为什么,本地改了只适用于本地,别人的
          #unittest框架不能修改,这样别人就没法用
          url: /dssform/formData/saveFormData,  #接口url--> 接口所需要的url,可以省略,非必填项，注意：若此url不写，则外层
          #url必须写否者接口找不到资源路由地址
          level: 中,   #级别--> 用例优先级,可以省略
          author: 陈建波,  #作者 --> 用例编写者,可以省略
          bar: {"appId":2,"cateId":null,"showCaseId":null,"attributeId":0,"pcStatus":null,"moStatus":null,"startDate":"","endDate":"","keyword":"","pageSize":15,"pageNumber":1,"orderColumn":"","order_productName":"","order_productCode":"","order_cateName":"","order_retailPrice":"","order_publishTime":"","order_pcStatus":"","order_moStatus":"","order_shortUrl":""},
          #用例用到的参数,无参数,可以不写,有参数必须写
          case_name: 产品列表,    #用例描述,该字段值会自动填充到你的用例代码注释中,让人明白你的这条用例功能 ,此字段可以省略
          expected: [200,'success'],  # 预期结果--> 用例预期值,多个预期值,请用数组，此字段为必填项
          mode: post,  # 请求类型 --> 接口请求方式，该数据会自动填充到用例代码中
          re_bar: json, # 请求参数 -->接口参数以什么数据格式传递到后台,数据自动填充到代码中
          }'''

pypublic = '''
# coding=utf-8
from time import sleep

import requests
from Common.CusMethod import random_str, random_letter, random_code, get_data_time
from Common.ReExecution import NumberCycles
from Common.ReadWriteIni import ReadWrite
from Common.ReadYaml import ReadPublic, ConfigYaml, ReadKeyWorld
from Common.Login import Login
from random import choice

class %sData:

    def __init__(self):
        """
        关于产品模块相关公共数据类接口数据
        """
        self.login = Login
        self.token_key = ConfigYaml('token_key').base_config
        self.token_value = ReadWrite().read_ini_token()
        self.headers = {self.login.content_type_key: self.login.content_json_type_value,
                        self.token_key: self.token_value}

        self.warehouse_name = ConfigYaml('wawarehouse_name').base_config
        self.matching_world = ConfigYaml('matching_world').base_config
        self.channle_name = ConfigYaml('channle_name').base_config

        self.dir = "%s"
        self.key_world = ReadKeyWorld(catalog="%s")
'''

publicyaml = '''add_customer:
  url: /add/customerParam
  bar: {}
'''



html_head = """<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
    <title>接口自动化测试报告</title>
    <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="https://www.echartsjs.com/examples/vendors/echarts/echarts.min.js"></script>
    <script type="text/javascript" src="https://www.echartsjs.com/examples/vendors/echarts-stat/ecStat.min.js"></script>
    <script type="text/javascript" src="https://www.echartsjs.com/examples/vendors/echarts/map/js/china.js"></script>
    <script type="text/javascript" src="https://www.echartsjs.com/examples/vendors/echarts/map/js/world.js"></script>
    <script type="text/javascript" src="https://www.echartsjs.com/examples/vendors/echarts/extension/dataTool.js"></script>
    <link href="../static/mycss.css" rel="stylesheet">
    <script src="../static/alljs.js"></script>
</head>
<body>
"""

html_body = '''
<div>
    <h1>Scrm接口自动化测试报告</h1>
    <hr>
    <div class="staticdis">
        <div>
            <table class="table table-bordered">
                <tbody>
                <tr>
                    <td>项目版本</td>
                    <td>{}</td>
                    <td>测试环境</td>
                    <td>{}</td>
                </tr>
                <tr>
                    <td>用例执行数</td>
                    <td>{}</td>
                    <td>执行总用时</td>
                    <td>{}</td>
                </tr>
                <tr>
                    <td>开始时间</td>
                    <td>{}</td>
                    <td>结束时间</td>
                    <td>{}</td>
                </tr>
                <tr>
                    <td>用时最长</td>
                    <td>{}</td>
                    <td>用时最短</td>
                    <td>{}</td>
                </tr>
                <tr>
                    <td>平均时长</td>
                    <td>{}</td>
                    <td>成功率</td>
                    <td>{}</td>
                </tr>
                </tbody>
            </table>
        </div>
        <div id="picture">
            <script>
                statistical({}, {}, {}, {}, {});
            </script>
        </div>
    </div>
'''
html_button = '''
<div class="button">
        <div><a href="#all" data-toggle="tab">全部({})</a></div>
        <div><a href="#success" data-toggle="tab">成功({})</a></div>
        <div><a href="#fail" data-toggle="tab">失败({})</a></div>
        <div><a href="#error" data-toggle="tab">错误({})</a></div>
        <div><a href="#timeout" data-toggle="tab">超时({})</a></div>
        <div><a href="#skip" data-toggle="tab">跳过({})</a></div>
    </div>
'''

html_all = '''
<div class="tab-content content" id="content">
    <div class="tab-pane active" id="all">
        <table class="table table-hover other">
            <thead>
                <tr>
                    <td>用例名称</td>
                    <td>用例描述</td>
                    <td>优先级</td>
                    <td>接口地址</td>
                    <td>测试结果</td>
                    <td>负责人</td>
                    <td>用时时间</td>
                    <td>详细信息</td>
                </tr>
            </thead>
'''
html_all_case = '''
<tr>
    <td>{}</td>
    <td>{}</td>
    <td>{}</td>
    <td>{}</td>
    <td>{}</td>
    <td>{}</td>
    <td>{}</td>
    <td><a href="javascript:showClassDetail('{}_{}','hidd_{}_{}')" id="{}_{}">详细</a></td>
</tr>
    <tr class='hiddenRow' id="hidd_{}_{}">
        <td colspan='8'>
            <div>
               <pre class="text-left">
{}
               </pre>
            </div>
        </td>
    </tr>
'''

html_all_end = '''
    </table>
</div>
'''

html_sum__end = '''
        </div>
    </body>
</html>
'''


html_other = '''
<div class="tab-pane" id="{}">
    <table class="table table-hover other">
        <thead>
            <tr>
                <td>用例名称</td>
                <td>用例描述</td>
                <td>优先级</td>
                <td>接口地址</td>
                <td>测试结果</td>
                <td>负责人</td>
                <td>用时时间</td>
                <td>详细信息</td>
            </tr>
        </thead>
        
'''
